/*************************************/
/********** INFORM CREATION **********/
/*************************************/
IXML_Document *createInform(SoapHeader *sh, DeviceIdStruct deviceId, EventList *events, unsigned int maxEnvelope, DateTime currentTime, unsigned int retryCount, ParameterValueList *parameterList) {
	IXML_Document *doc = ixmlDocument_createDocument();
	
	IXML_Element *envelope= ixmlDocument_createElementNS(doc, "http://schemas.xmlsoap.org/soap/envelope/", "soap:Envelope");
	ixmlElement_setAttribute(envelope,"xmlns:soap","http://schemas.xmlsoap.org/soap/envelope/" );
	ixmlElement_setAttribute(envelope,"soap:encodingStyle","http://schemas.xmlsoap.org/soap/encoding/" );
	ixmlElement_setAttribute(envelope,"xmlns:xsi", "http://www.w3.org/2001/XMLSchema/instance/" );
	ixmlElement_setAttribute(envelope,"xmlns:xsd", "http://www.w3.org/2001/XMLSchema/" );
	ixmlElement_setAttribute(envelope,"xmlns:cwmp", "urn:dslforum-org:cwmp-1-0" );

		
	ixmlNode_appendChild( (IXML_Node *)doc,(IXML_Node *) envelope);

	if(sh!=NULL) {
		IXML_Node *header = createHeader(doc, sh);
		ixmlNode_appendChild( (IXML_Node *)envelope,(IXML_Node *)header);	
	}
	
	IXML_Element *body= ixmlDocument_createElementNS(doc, "http://schemas.xmlsoap.org/soap/envelope/", "soap:Body");
	ixmlNode_appendChild( (IXML_Node *)envelope,(IXML_Node *)body);

	IXML_Element *inform=ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "cwmp:Inform");
	ixmlNode_appendChild( (IXML_Node *)body,(IXML_Node *)inform);

	IXML_Element *devid = createDeviceId(doc, &deviceId);
	IXML_Element *evt = createEvent(doc, events);
	IXML_Element *maxenv=createMaxEnvelope(doc, maxEnvelope);
	IXML_Element *dt=createDateTime(doc, &currentTime);
	IXML_Element *retrcou=createRetryCount(doc, retryCount);
	IXML_Element *parlist=createParameterList(doc, parameterList);


	ixmlNode_appendChild( (IXML_Node *)inform,(IXML_Node *)devid);
	ixmlNode_appendChild( (IXML_Node *)inform,(IXML_Node *)evt);
	ixmlNode_appendChild( (IXML_Node *)inform,(IXML_Node *)maxenv);
	ixmlNode_appendChild( (IXML_Node *)inform,(IXML_Node *)dt);
	ixmlNode_appendChild( (IXML_Node *)inform,(IXML_Node *)retrcou);
	ixmlNode_appendChild( (IXML_Node *)inform,(IXML_Node *)parlist);

	return doc;

}

IXML_Document *createInformResponse(SoapHeader *sh, unsigned int maxEnvelope) {
	IXML_Document *doc = ixmlDocument_createDocument();
	
	IXML_Element *envelope= ixmlDocument_createElementNS(doc, "http://schemas.xmlsoap.org/soap/envelope/", "soap:Envelope");
	ixmlElement_setAttribute(envelope,"xmlns:soap","http://schemas.xmlsoap.org/soap/envelope/" );
	ixmlElement_setAttribute(envelope,"soap:encodingStyle","http://schemas.xmlsoap.org/soap/encoding/" );
	ixmlElement_setAttribute(envelope,"xmlns:cwmp", "urn:dslforum-org:cwmp-1-0" );
	ixmlNode_appendChild( (IXML_Node *)doc,(IXML_Node *) envelope);

	if(sh!=NULL) {
		IXML_Node *header = createHeader(doc, sh);
		ixmlNode_appendChild( (IXML_Node *)envelope,(IXML_Node *)header);	
	}

	IXML_Element *body= ixmlDocument_createElementNS(doc, "http://schemas.xmlsoap.org/soap/envelope/", "soap:Body");
	ixmlNode_appendChild( (IXML_Node *)envelope,(IXML_Node *)body);

	IXML_Element *informresp=ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "cwmp:InformResponse");
	ixmlNode_appendChild( (IXML_Node *)body,(IXML_Node *)informresp);
	IXML_Element *maxenv=createMaxEnvelope(doc, maxEnvelope);
	ixmlNode_appendChild( (IXML_Node *)informresp,(IXML_Node *)maxenv);
	return doc;
}

IXML_Element *createDeviceId(IXML_Document* doc, DeviceIdStruct *deviceId) {
	IXML_Element *el=ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "DeviceId");
	ixmlElement_setAttribute(el,"xsi:type","cwmp:DeviceIdStruct" );	

	IXML_Element *manuf=ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "Manufacturer");
	IXML_Node* manuf_text=ixmlDocument_createTextNode(doc, deviceId->manufactorer);
	ixmlElement_setAttribute(manuf,"xsi:type","xsd:string[64]" );
	ixmlNode_appendChild( (IXML_Node *) manuf, manuf_text);
	
	IXML_Element *oui=ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "OUI");
	IXML_Node* oui_text=ixmlDocument_createTextNode(doc, deviceId->OUI);
	ixmlElement_setAttribute(oui,"xsi:type","xsd:string[6]" );
	ixmlNode_appendChild( (IXML_Node *) oui, oui_text);	

	IXML_Element *prclass=ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "ProductClass");
	IXML_Node* prclass_text=ixmlDocument_createTextNode(doc, deviceId->productClass);
	ixmlElement_setAttribute(prclass,"xsi:type","xsd:string[64]" );
	ixmlNode_appendChild( (IXML_Node *) prclass, prclass_text);	

	
	IXML_Element *sn=ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "SerialNumber");
	IXML_Node* sn_text=ixmlDocument_createTextNode(doc, deviceId->serialNumber);
	ixmlElement_setAttribute(sn,"xsi:type","xsd:string[64]" );
	ixmlNode_appendChild( (IXML_Node *) sn, sn_text);	

	ixmlNode_appendChild( (IXML_Node *)el, (IXML_Node *)manuf );
	ixmlNode_appendChild( (IXML_Node *)el, (IXML_Node *)oui );
	ixmlNode_appendChild( (IXML_Node *)el, (IXML_Node *)prclass );
	ixmlNode_appendChild( (IXML_Node *)el, (IXML_Node *)sn );

	return el;
}

IXML_Element *createEvent(IXML_Document* doc, EventList *events) { 

	IXML_Element *el=ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "Event");
	char a[40];
	sprintf(a, "cwmp:EventStruct[%d]", events->size );
	ixmlElement_setAttribute(el,"soap:arrayType",a );	
	
	unsigned int i;

	for(i=0;i<events->size;i++) {
		IXML_Element *el1=ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "EventCode");
		IXML_Node* el1_text=ixmlDocument_createTextNode(doc, events->events[i].eventCode );
		ixmlElement_setAttribute(el1,"xsi:type","xsd:string[64]" );
		ixmlNode_appendChild( (IXML_Node *) el1, (IXML_Node *) el1_text);

		ixmlNode_appendChild( (IXML_Node *) el, (IXML_Node *) el1);
	}

	return el;

}

IXML_Element *createMaxEnvelope(IXML_Document* doc, unsigned int maxEnvelope) {
	IXML_Element *el=ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "MaxEnvelopes");
	ixmlElement_setAttribute(el,"xsi:type","xsd:unsignedInt" );
	char *buf = (char *)malloc(4*sizeof(char) ) ;
	sprintf(buf, "%d", maxEnvelope);
	IXML_Node* el_text=ixmlDocument_createTextNode(doc, buf);
	ixmlNode_appendChild( (IXML_Node *) el, el_text);
	return el;
}

IXML_Element *createDateTime(IXML_Document* doc, DateTime *currentTime) { 
	IXML_Element *el=ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "CurrentTime");
	char *dt = datetoasci(currentTime);
	ixmlElement_setAttribute(el,"xsi:type","xsd:dateTime" );	
	IXML_Node* el_text=ixmlDocument_createTextNode(doc, dt);
	ixmlNode_appendChild( (IXML_Node *) el, el_text);
//	free(dt);
	return el;
}

IXML_Element *createRetryCount(IXML_Document* doc, unsigned int retryCount) { 
	IXML_Element *el=ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "RetryCount");
	ixmlElement_setAttribute(el,"xsi:type","xsd:unsignedInt" );
	char *buf = (char *)malloc(4*sizeof(char) ) ;
	sprintf(buf, "%d", retryCount);
	IXML_Node* el_text=ixmlDocument_createTextNode(doc, buf );
	ixmlNode_appendChild( (IXML_Node *) el, el_text);
	return el;
}

IXML_Element *createParameterList(IXML_Document* doc, ParameterValueList *parameterList) { 
	IXML_Element *el=ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "ParameterList");
	char a[50];
	sprintf(a, "cwmp:ParameterValueStruct[%d]", parameterList->size);
	ixmlElement_setAttribute(el,"soap:arrayType",a );	
	
	unsigned int i;

	for(i=0;i<parameterList->size;i++) {
		IXML_Element *el1=ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "ParameterValueStruct");

		IXML_Element *name=ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "Name");
		IXML_Node* name_text=ixmlDocument_createTextNode(doc, parameterList->parameters[i].name );
		ixmlElement_setAttribute(name,"xsi:type","xsd:string" );	
		ixmlNode_appendChild( (IXML_Node *) name, (IXML_Node *) name_text);

		IXML_Element *value=ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "Value");
		IXML_Node* value_text=ixmlDocument_createTextNode(doc, parameterList->parameters[i].value );
		ixmlElement_setAttribute(value,"xsi:type","xsd:string" );
		ixmlNode_appendChild( (IXML_Node *) value, (IXML_Node *) value_text);

		ixmlNode_appendChild( (IXML_Node *) el1, (IXML_Node *) name);
		ixmlNode_appendChild( (IXML_Node *) el1, (IXML_Node *) value);
		ixmlNode_appendChild( (IXML_Node *) el, (IXML_Node *) el1);
	}

	return el;
	
}



/**************************************************/
/********** GETPARAMETER VALUES CREATION **********/
/**************************************************/

IXML_Document *createGetParameterValues(SoapHeader *sh, StringList *parameterNames) {
	IXML_Document *doc = ixmlDocument_createDocument();
	
	IXML_Element *envelope= ixmlDocument_createElementNS(doc, "http://schemas.xmlsoap.org/soap/envelope/", "soap:Envelope");
	ixmlElement_setAttribute(envelope,"xmlns:soap","http://schemas.xmlsoap.org/soap/envelope/" );
	ixmlElement_setAttribute(envelope,"soap:encodingStyle","http://schemas.xmlsoap.org/soap/encoding/" );
	ixmlElement_setAttribute(envelope,"xmlns:cwmp", "urn:dslforum-org:cwmp-1-0" );
	ixmlNode_appendChild( (IXML_Node *)doc,(IXML_Node *) envelope);

	if(sh!=NULL) {
		IXML_Node *header = createHeader(doc, sh);
		ixmlNode_appendChild( (IXML_Node *)envelope,(IXML_Node *)header);	
	}


	IXML_Element *body=ixmlDocument_createElementNS(doc, "http://schemas.xmlsoap.org/soap/envelope/", "soap:Body");
	ixmlNode_appendChild( (IXML_Node *)envelope,(IXML_Node *)body);


	IXML_Element *inform=ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "cwmp:GetParameterValues");
	ixmlNode_appendChild( (IXML_Node *)body,(IXML_Node *)inform);

	IXML_Element *parlist=createParameterNames(doc, parameterNames);

	ixmlNode_appendChild( (IXML_Node *)inform,(IXML_Node *)parlist);

	return doc;

}

IXML_Document *createGetParameterValuesResponse(SoapHeader *sh, ParameterValueList *parameterList) {
	IXML_Document *doc = ixmlDocument_createDocument();
	
	IXML_Element *envelope= ixmlDocument_createElementNS(doc, "http://schemas.xmlsoap.org/soap/envelope/", "soap:Envelope");
	ixmlElement_setAttribute(envelope,"xmlns:soap","http://schemas.xmlsoap.org/soap/envelope/" );
	ixmlElement_setAttribute(envelope,"soap:encodingStyle","http://schemas.xmlsoap.org/soap/encoding/" );
	ixmlElement_setAttribute(envelope,"xmlns:xsi", "http://www.w3.org/2001/XMLSchema/instance/" );
	ixmlElement_setAttribute(envelope,"xmlns:xsd", "http://www.w3.org/2001/XMLSchema/" );
	ixmlElement_setAttribute(envelope,"xmlns:cwmp", "urn:dslforum-org:cwmp-1-0" );
	ixmlNode_appendChild( (IXML_Node *)doc,(IXML_Node *) envelope);
	
	if(sh!=NULL) {
		IXML_Node *header = createHeader(doc, sh);
		ixmlNode_appendChild( (IXML_Node *)envelope,(IXML_Node *)header);	
	}

	IXML_Element *body=ixmlDocument_createElementNS(doc, "http://schemas.xmlsoap.org/soap/envelope/", "soap:Body");
	ixmlNode_appendChild( (IXML_Node *)envelope,(IXML_Node *)body);


	IXML_Element *inform=ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "cwmp:GetParameterValuesResponse");
	ixmlNode_appendChild( (IXML_Node *)body,(IXML_Node *)inform);

	IXML_Element *parlist=createParameterList(doc, parameterList);

	ixmlNode_appendChild( (IXML_Node *)inform,(IXML_Node *)parlist);

	return doc;

}

IXML_Element *createParameterNames(IXML_Document *doc, StringList *parameterNames) {
	IXML_Element *el=ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "ParameterNames");
	char a[50];
	sprintf(a, "cwmp:ParameterValueStruct[%d]", parameterNames->size);
	ixmlElement_setAttribute(el,"soap:arrayType",a );	

	unsigned int i;	

	for(i=0;i<parameterNames->size;i++) {
		IXML_Element *el1=ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "ParameterName");

		IXML_Node* el1_text=ixmlDocument_createTextNode(doc, parameterNames->strings[i] );
		ixmlElement_setAttribute(el1,"xsi:type","xsd:string" );	
		ixmlNode_appendChild( (IXML_Node *) el1, (IXML_Node *) el1_text);

		ixmlNode_appendChild( (IXML_Node *) el, (IXML_Node *) el1);
	}
	return el;
}



/*************************************************/
/********** SETPARAMETERVALUES CREATION **********/
/*************************************************/

IXML_Document *createSetParameterValues(SoapHeader *sh, ParameterValueList *parameterList, char *parameterKey) {
	IXML_Document *doc = ixmlDocument_createDocument();
	
	IXML_Element *envelope= ixmlDocument_createElementNS(doc, "http://schemas.xmlsoap.org/soap/envelope/", "soap:Envelope");
	ixmlElement_setAttribute(envelope,"xmlns:soap","http://schemas.xmlsoap.org/soap/envelope/" );
	ixmlElement_setAttribute(envelope,"soap:encodingStyle","http://schemas.xmlsoap.org/soap/encoding/" );
	ixmlElement_setAttribute(envelope,"xmlns:xsi", "http://www.w3.org/2001/XMLSchema/instance/" );
	ixmlElement_setAttribute(envelope,"xmlns:xsd", "http://www.w3.org/2001/XMLSchema/" );
	ixmlElement_setAttribute(envelope,"xmlns:cwmp", "urn:dslforum-org:cwmp-1-0" );
	ixmlNode_appendChild( (IXML_Node *)doc,(IXML_Node *) envelope);

	if(sh!=NULL) {
		IXML_Node *header = createHeader(doc, sh);
		ixmlNode_appendChild( (IXML_Node *)envelope,(IXML_Node *)header);	
	}

	IXML_Element *body=ixmlDocument_createElementNS(doc, "http://schemas.xmlsoap.org/soap/envelope/", "soap:Body");
	ixmlNode_appendChild( (IXML_Node *)envelope,(IXML_Node *)body);


	IXML_Element *setparval=ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "cwmp:SetParameterValues");
	ixmlNode_appendChild( (IXML_Node *)body,(IXML_Node *)setparval);

	IXML_Element *parlist=createParameterList(doc, parameterList);

	ixmlNode_appendChild( (IXML_Node *)setparval,(IXML_Node *)parlist);


	IXML_Element *parkey = ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "ParameterKey");
	IXML_Node *parkey_text =ixmlDocument_createTextNode(doc, parameterKey);
	ixmlNode_appendChild( (IXML_Node *)parkey,(IXML_Node *)parkey_text);
	ixmlNode_appendChild( (IXML_Node *)setparval,(IXML_Node *)parkey);

	return doc;

}


IXML_Document *createSetParameterValuesResponse(SoapHeader *sh, int status) {
	IXML_Document *doc = ixmlDocument_createDocument();
	
	IXML_Element *envelope= ixmlDocument_createElementNS(doc, "http://schemas.xmlsoap.org/soap/envelope/", "soap:Envelope");
	ixmlElement_setAttribute(envelope,"xmlns:soap","http://schemas.xmlsoap.org/soap/envelope/" );
	ixmlElement_setAttribute(envelope,"soap:encodingStyle","http://schemas.xmlsoap.org/soap/encoding/" );
	ixmlElement_setAttribute(envelope,"xmlns:cwmp", "urn:dslforum-org:cwmp-1-0" );
	ixmlNode_appendChild( (IXML_Node *)doc,(IXML_Node *) envelope);

	if(sh!=NULL) {
		IXML_Node *header = createHeader(doc, sh);
		ixmlNode_appendChild( (IXML_Node *)envelope,(IXML_Node *)header);	
	}

	IXML_Element *body=ixmlDocument_createElementNS(doc, "http://schemas.xmlsoap.org/soap/envelope/", "soap:Body");
	ixmlNode_appendChild( (IXML_Node *)envelope,(IXML_Node *)body);

	IXML_Element *inform=ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "cwmp:SetParameterValuesResponse");
	ixmlNode_appendChild( (IXML_Node *)body,(IXML_Node *)inform);

	IXML_Element *stat=createStatus(doc, status);

	ixmlNode_appendChild( (IXML_Node *)inform,(IXML_Node *)stat);

	return doc;
}

IXML_Element *createStatus(IXML_Document* doc, unsigned int status) {
	IXML_Element *stat=ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "Status");
	char *buf = (char *)malloc(4*sizeof(char) ) ;
	sprintf(buf, "%d", status);
	IXML_Node* stat_text=ixmlDocument_createTextNode(doc, buf);
	ixmlNode_appendChild( (IXML_Node *) stat, stat_text);
	return stat;
}


/*************************************************/
/*********** GETPARAMETERNAMES CREATION **********/
/*************************************************/

IXML_Document *createGetParameterNames(SoapHeader *sh, char *parameterPath, unsigned short int nextLevel) {
	IXML_Document *doc = ixmlDocument_createDocument();
	
	IXML_Element *envelope= ixmlDocument_createElementNS(doc, "http://schemas.xmlsoap.org/soap/envelope/", "soap:Envelope");
	ixmlElement_setAttribute(envelope,"xmlns:soap","http://schemas.xmlsoap.org/soap/envelope/" );
	ixmlElement_setAttribute(envelope,"soap:encodingStyle","http://schemas.xmlsoap.org/soap/encoding/" );
	ixmlElement_setAttribute(envelope,"xmlns:cwmp", "urn:dslforum-org:cwmp-1-0" );
	ixmlNode_appendChild( (IXML_Node *)doc,(IXML_Node *) envelope);

	if(sh!=NULL) {
		IXML_Node *header = createHeader(doc, sh);
		ixmlNode_appendChild( (IXML_Node *)envelope,(IXML_Node *)header);	
	}

	IXML_Element *body=ixmlDocument_createElementNS(doc, "http://schemas.xmlsoap.org/soap/envelope/", "soap:Body");
	ixmlNode_appendChild( (IXML_Node *)envelope,(IXML_Node *)body);


	IXML_Element *inform=ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "cwmp:GetParameterNames");
	ixmlNode_appendChild( (IXML_Node *)body,(IXML_Node *)inform);

	IXML_Element *parpath=ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "ParameterPath");
	IXML_Node* parpath_text=ixmlDocument_createTextNode(doc, parameterPath);
	ixmlNode_appendChild( (IXML_Node *)parpath,(IXML_Node *)parpath_text);
	
	IXML_Element *nextlev=ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "NextLevel");
	char *nl;
	if(nextLevel==0) nl = "false"; else nl="true";
	IXML_Node* nextlev_text=ixmlDocument_createTextNode(doc, nl );
	ixmlNode_appendChild( (IXML_Node *)nextlev,(IXML_Node *)nextlev_text);

	ixmlNode_appendChild( (IXML_Node *)inform,(IXML_Node *)parpath);
	ixmlNode_appendChild( (IXML_Node *)inform,(IXML_Node *)nextlev);

	return doc;

}


IXML_Document *createGetParameterNamesResponse(SoapHeader *sh, char *path, unsigned short nextLevel){
	unsigned int i;
	IXML_Document *doc = ixmlDocument_createDocument();
	
	IXML_Element *envelope= ixmlDocument_createElementNS(doc, "http://schemas.xmlsoap.org/soap/envelope/", "soap:Envelope");
	ixmlElement_setAttribute(envelope,"xmlns:soap","http://schemas.xmlsoap.org/soap/envelope/" );
	ixmlElement_setAttribute(envelope,"soap:encodingStyle","http://schemas.xmlsoap.org/soap/encoding/" );
	ixmlElement_setAttribute(envelope,"xmlns:xsi", "http://www.w3.org/2001/XMLSchema/instance/" );
	ixmlElement_setAttribute(envelope,"xmlns:xsd", "http://www.w3.org/2001/XMLSchema/" );
	ixmlElement_setAttribute(envelope,"xmlns:cwmp", "urn:dslforum-org:cwmp-1-0" );
	ixmlNode_appendChild( (IXML_Node *)doc,(IXML_Node *) envelope);

	if(sh!=NULL) {
		IXML_Node *header = createHeader(doc, sh);
		ixmlNode_appendChild( (IXML_Node *)envelope,(IXML_Node *)header);	
	}

	IXML_Element *body=ixmlDocument_createElementNS(doc, "http://schemas.xmlsoap.org/soap/envelope/", "soap:Body");
	ixmlNode_appendChild( (IXML_Node *)envelope,(IXML_Node *)body);

	IXML_Element *response=ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "cwmp:GetParameterNamesResponse");
	ixmlNode_appendChild( (IXML_Node *)body,(IXML_Node *)response);

	// Gia arxh de 9a lhf9ei up' oyin to nextLevel
	
	//IXML_Element *plist= ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "ParameterList");
	
	
	if(strcmp(path, "")==0) { //Adeio path
		IXML_Element *parameterList = ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "ParameterList");
		ixmlElement_setAttribute(parameterList,"xmlns:soap","http://schemas.xmlsoap.org/soap/envelope/" );
		char a[50];
		sprintf(a, "cwmp:ParameterInfoStruct[%d]", NUMOFVARS);
		ixmlElement_setAttribute(parameterList,"soap:arrayType",a );	
		ixmlNode_appendChild( (IXML_Node *)response,(IXML_Node *)parameterList);

		for(i=0;i<NUMOFVARS;i++) {
			IXML_Element *el = ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "ParameterInfoStruct");

			IXML_Element *name = ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "Name");
			IXML_Node *name_text = ixmlDocument_createTextNode(doc, deviceVariables[i].name);
			ixmlNode_appendChild( (IXML_Node *)name,(IXML_Node *)name_text);

			IXML_Element *writable = ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "Writable");
			IXML_Node *writable_text = ixmlDocument_createTextNode(doc, (char *)(deviceVariables[i].writable?"true":"false"));
			ixmlNode_appendChild( (IXML_Node *)writable,(IXML_Node *)writable_text);

			ixmlNode_appendChild( (IXML_Node *)el,(IXML_Node *)name);
			ixmlNode_appendChild( (IXML_Node *)el,(IXML_Node *)writable);
			ixmlNode_appendChild( (IXML_Node *)parameterList,(IXML_Node *)el);
		}
	}

	for(i=0;i<NUMOFVARS;i++) {
		
		if(strncmp(path, deviceVariables[i].name, strlen(path) )==0) {
			

		}
	}


	return doc;
}

/**************************************************/
/************ GET RPC METHODS CREATION ************/
/**************************************************/


IXML_Document *createGetRPCMethods(SoapHeader *sh) {
	// De to xrhsimopoiei o client
	return NULL;
}


IXML_Document *createGetRPCMethodsResponse(SoapHeader *sh) {
	int i;
	static char * methods[7] = {
		"GetRPCMethods",
		"SetParameterValues",
		"GetParameterValues",
		"GetParameterNames",
		"Download",
		"Upload",
		"Reboot"
	};

	IXML_Document *doc = ixmlDocument_createDocument();
	
	IXML_Element *envelope= ixmlDocument_createElementNS(doc, "http://schemas.xmlsoap.org/soap/envelope/", "soap:Envelope");
	ixmlElement_setAttribute(envelope,"xmlns:soap","http://schemas.xmlsoap.org/soap/envelope/" );
	ixmlElement_setAttribute(envelope,"xmlns:xsd", "http://www.w3.org/2001/XMLSchema/" );
	ixmlElement_setAttribute(envelope,"xmlns:xsi", "http://www.w3.org/2001/XMLSchema/instance/" );
	ixmlElement_setAttribute(envelope,"soap:encodingStyle","http://schemas.xmlsoap.org/soap/encoding/" );
	ixmlElement_setAttribute(envelope,"xmlns:cwmp", "urn:dslforum-org:cwmp-1-0" );
	ixmlNode_appendChild( (IXML_Node *)doc,(IXML_Node *) envelope);

	if(sh!=NULL) {
		IXML_Node *header = createHeader(doc, sh);
		ixmlNode_appendChild( (IXML_Node *)envelope,(IXML_Node *)header);	
	}

	IXML_Element *body=ixmlDocument_createElementNS(doc, "http://schemas.xmlsoap.org/soap/envelope/", "soap:Body");
	ixmlNode_appendChild( (IXML_Node *)envelope,(IXML_Node *)body);


	IXML_Element *getrpc=ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "cwmp:GetRPCMethodsResponse");
	ixmlNode_appendChild( (IXML_Node *)body,(IXML_Node *)getrpc);



	IXML_Element *methodList = ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "MethodList");
	ixmlElement_setAttribute(methodList,"xmlns:soap","http://schemas.xmlsoap.org/soap/envelope/" );
	ixmlElement_setAttribute(methodList,"soap:arrayType","xsd:string[64][7]" );	
	ixmlNode_appendChild( (IXML_Node *)getrpc,(IXML_Node *)methodList);

	for(i=0;i<7;i++) {
		IXML_Element *meth = ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "Method");
		IXML_Node *meth_text = ixmlDocument_createTextNode(doc, methods[i]);
		ixmlNode_appendChild( (IXML_Node *)meth,(IXML_Node *)meth_text);
		ixmlNode_appendChild( (IXML_Node *)methodList,(IXML_Node *)meth);
	}

	return doc;



}

/**************************************************/
/**************** REBOOT CREATION *****************/
/**************************************************/

IXML_Document *createReboot(SoapHeader *sh, char *cmdKey) {
	// De to xrhsimopoiei o client
	return NULL;
}

IXML_Document *createRebootResponse(SoapHeader *sh) {
	IXML_Document *doc = ixmlDocument_createDocument();
	
	IXML_Element *envelope= ixmlDocument_createElementNS(doc, "http://schemas.xmlsoap.org/soap/envelope/", "soap:Envelope");
	ixmlElement_setAttribute(envelope,"xmlns:soap","http://schemas.xmlsoap.org/soap/envelope/" );
	ixmlElement_setAttribute(envelope,"soap:encodingStyle","http://schemas.xmlsoap.org/soap/encoding/" );
	ixmlElement_setAttribute(envelope,"xmlns:cwmp", "urn:dslforum-org:cwmp-1-0" );
	ixmlNode_appendChild( (IXML_Node *)doc,(IXML_Node *) envelope);

	if(sh!=NULL) {
		IXML_Node *header = createHeader(doc, sh);
		ixmlNode_appendChild( (IXML_Node *)envelope,(IXML_Node *)header);	
	}

	IXML_Element *body=ixmlDocument_createElementNS(doc, "http://schemas.xmlsoap.org/soap/envelope/", "soap:Body");
	ixmlNode_appendChild( (IXML_Node *)envelope,(IXML_Node *)body);


	IXML_Element *rebresp=ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "cwmp:RebootResponse");
	ixmlNode_appendChild( (IXML_Node *)body,(IXML_Node *)rebresp);

	return doc;

}


/**************************************************/
/*************** DOWNLOAD CREATION ****************/
/**************************************************/

IXML_Document *createDownload(SoapHeader *sh, char *cmdKey, char *ftype, char *URL, char *uname, char *pwd, unsigned int fsize, char *tgetfname, unsigned int dsecs, char *surl, char *furl) {
	// De to xrhsimopoiei o client
	return NULL;
}


IXML_Document *createDownloadResponse(SoapHeader *sh, short int status, DateTime *startTime, DateTime *completeTime) {
	IXML_Document *doc = ixmlDocument_createDocument();
	
	IXML_Element *envelope= ixmlDocument_createElementNS(doc, "http://schemas.xmlsoap.org/soap/envelope/", "soap:Envelope");
	ixmlElement_setAttribute(envelope,"xmlns:soap","http://schemas.xmlsoap.org/soap/envelope/" );
	ixmlElement_setAttribute(envelope,"soap:encodingStyle","http://schemas.xmlsoap.org/soap/encoding/" );
	ixmlElement_setAttribute(envelope,"xmlns:cwmp", "urn:dslforum-org:cwmp-1-0" );
	ixmlNode_appendChild( (IXML_Node *)doc,(IXML_Node *) envelope);

	if(sh!=NULL) {
		IXML_Node *header = createHeader(doc, sh);
		ixmlNode_appendChild( (IXML_Node *)envelope,(IXML_Node *)header);	
	}

	IXML_Element *body=ixmlDocument_createElementNS(doc, "http://schemas.xmlsoap.org/soap/envelope/", "soap:Body");
	ixmlNode_appendChild( (IXML_Node *)envelope,(IXML_Node *)body);


	IXML_Element *dresp=ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "cwmp:DownloadResponse");
	ixmlNode_appendChild( (IXML_Node *)body,(IXML_Node *)dresp);

	IXML_Element *stat=ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "Status");
	char a[10];
	sprintf(a,"%d", status);
	IXML_Node* stat_text=ixmlDocument_createTextNode(doc, a);
	ixmlNode_appendChild( (IXML_Node *)stat,(IXML_Node *)stat_text);

	ixmlNode_appendChild( (IXML_Node *)dresp,(IXML_Node *)stat);

	IXML_Element *stime=ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "StartTime");
	ixmlNode_appendChild( (IXML_Node *)dresp,(IXML_Node *)stime);
	if(startTime!=NULL) {
		IXML_Node* stime_text=ixmlDocument_createTextNode(doc, datetoasci(startTime) );
		ixmlNode_appendChild( (IXML_Node *)stime,(IXML_Node *)stime_text);
	}

	IXML_Element *ctime=ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "CompleteTime");
	ixmlNode_appendChild( (IXML_Node *)dresp,(IXML_Node *)ctime);
	if(completeTime!=NULL) {
		IXML_Node* ctime_text=ixmlDocument_createTextNode(doc, datetoasci(completeTime) );
		ixmlNode_appendChild( (IXML_Node *)ctime,(IXML_Node *)ctime_text);
	}


	return doc;
}

/**************************************************/
/**************** UPLOAD CREATION *****************/
/**************************************************/


IXML_Document *createUpload(SoapHeader *sh, char *cmdKey, char *ftype, char *URL, char *uname, char *pwd, unsigned int dsecs) {
	// De to xrhsimopoiei o client
	return NULL;
}

IXML_Document *createUploadResponse(SoapHeader *sh, short int status, DateTime *startTime, DateTime *completeTime) {
	IXML_Document *doc = ixmlDocument_createDocument();
	
	IXML_Element *envelope= ixmlDocument_createElementNS(doc, "http://schemas.xmlsoap.org/soap/envelope/", "soap:Envelope");
	ixmlElement_setAttribute(envelope,"xmlns:soap","http://schemas.xmlsoap.org/soap/envelope/" );
	ixmlElement_setAttribute(envelope,"soap:encodingStyle","http://schemas.xmlsoap.org/soap/encoding/" );
	ixmlElement_setAttribute(envelope,"xmlns:cwmp", "urn:dslforum-org:cwmp-1-0" );
	ixmlNode_appendChild( (IXML_Node *)doc,(IXML_Node *) envelope);

	if(sh!=NULL) {
		IXML_Node *header = createHeader(doc, sh);
		ixmlNode_appendChild( (IXML_Node *)envelope,(IXML_Node *)header);	
	}

	IXML_Element *body=ixmlDocument_createElementNS(doc, "http://schemas.xmlsoap.org/soap/envelope/", "soap:Body");
	ixmlNode_appendChild( (IXML_Node *)envelope,(IXML_Node *)body);


	IXML_Element *dresp=ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "cwmp:UploadResponse");
	ixmlNode_appendChild( (IXML_Node *)body,(IXML_Node *)dresp);

	IXML_Element *stat=ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "Status");
	char a[10];
	sprintf(a,"%d", status);
	IXML_Node* stat_text=ixmlDocument_createTextNode(doc, a);
	ixmlNode_appendChild( (IXML_Node *)stat,(IXML_Node *)stat_text);

	ixmlNode_appendChild( (IXML_Node *)dresp,(IXML_Node *)stat);

	IXML_Element *stime=ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "StartTime");
	ixmlNode_appendChild( (IXML_Node *)dresp,(IXML_Node *)stime);
	if(startTime!=NULL) {
		IXML_Node* stime_text=ixmlDocument_createTextNode(doc, datetoasci(startTime) );
		ixmlNode_appendChild( (IXML_Node *)stime,(IXML_Node *)stime_text);
	}

	IXML_Element *ctime=ixmlDocument_createElementNS(doc, "xmlns:cwmp=urn:dslforum-org:cwmp-1-0", "CompleteTime");
	ixmlNode_appendChild( (IXML_Node *)dresp,(IXML_Node *)ctime);
	if(completeTime!=NULL) {
		IXML_Node* ctime_text=ixmlDocument_createTextNode(doc, datetoasci(completeTime) );
		ixmlNode_appendChild( (IXML_Node *)ctime,(IXML_Node *)ctime_text);
	}


	return doc;
}

/**************************************************/
/**************** FAULT CREATION ******************/
/**************************************************/


IXML_Document *createFaultResponse(SoapHeader *sh, int code) {
	IXML_Document *doc = ixmlDocument_createDocument();
	
	IXML_Element *envelope= ixmlDocument_createElementNS(doc, "http://schemas.xmlsoap.org/soap/envelope/", "soap:Envelope");
	ixmlElement_setAttribute(envelope,"xmlns:soap","http://schemas.xmlsoap.org/soap/envelope/" );
	ixmlElement_setAttribute(envelope,"soap:encodingStyle","http://schemas.xmlsoap.org/soap/encoding/" );
	ixmlElement_setAttribute(envelope,"xmlns:cwmp", "urn:dslforum-org:cwmp-1-0" );
	ixmlNode_appendChild( (IXML_Node *)doc,(IXML_Node *) envelope);

	if(sh!=NULL) {
		IXML_Node *header = createHeader(doc, sh);
		ixmlNode_appendChild( (IXML_Node *)envelope,(IXML_Node *)header);	
	}

	IXML_Element *body=ixmlDocument_createElementNS(doc, "http://schemas.xmlsoap.org/soap/envelope/", "soap:Body");
	ixmlNode_appendChild( (IXML_Node *)envelope,(IXML_Node *)body);

	IXML_Element *fault=ixmlDocument_createElementNS(doc, "http://schemas.xmlsoap.org/soap/envelope/", "soap:Fault");
	ixmlNode_appendChild( (IXML_Node *)body,(IXML_Node *)fault);

	IXML_Element *faultcode=ixmlDocument_createElementNS(doc, "http://schemas.xmlsoap.org/soap/envelope/", "faultcode");
	ixmlNode_appendChild( (IXML_Node *)fault,(IXML_Node *)faultcode);
	IXML_Node *faultcode_text= ixmlDocument_createTextNode(doc,"Client");
	ixmlNode_appendChild( (IXML_Node *)faultcode,(IXML_Node *)faultcode_text);
	
	IXML_Element *faultstring=ixmlDocument_createElementNS(doc, "http://schemas.xmlsoap.org/soap/envelope/", "faultstring");
	ixmlNode_appendChild( (IXML_Node *)fault,(IXML_Node *)faultstring);
	IXML_Node *faultstring_text= ixmlDocument_createTextNode(doc,"CWMP fault");
	ixmlNode_appendChild( (IXML_Node *)faultstring,(IXML_Node *)faultstring_text);
	
	IXML_Element *detail = ixmlDocument_createElementNS(doc, "http://schemas.xmlsoap.org/soap/envelope/", "detail");
	ixmlNode_appendChild( (IXML_Node *)fault,(IXML_Node *)detail);

	IXML_Element *faultcwmp=ixmlDocument_createElementNS(doc, "urn:dslforum-org:cwmp-1-0", "cwmp:Fault");
	ixmlNode_appendChild( (IXML_Node *)detail,(IXML_Node *)faultcwmp);


	IXML_Element *faultcodecwmp=ixmlDocument_createElementNS(doc, "urn:dslforum-org:cwmp-1-0", "FaultCode");
	ixmlNode_appendChild( (IXML_Node *)faultcwmp,(IXML_Node *)faultcodecwmp);
	char a[5];
	sprintf(a, "%d", code);
	IXML_Node *faultcodecwmp_text= ixmlDocument_createTextNode(doc,a);
	ixmlNode_appendChild( (IXML_Node *)faultcodecwmp,(IXML_Node *)faultcodecwmp_text);
	
	IXML_Element *faultstringcwmp=ixmlDocument_createElementNS(doc, "urn:dslforum-org:cwmp-1-0", "FaultString");
	ixmlNode_appendChild( (IXML_Node *)faultcwmp,(IXML_Node *)faultstringcwmp);
	IXML_Node *faultstringcwmp_text= ixmlDocument_createTextNode(doc, getErrorByNum(code) );
	ixmlNode_appendChild( (IXML_Node *)faultstringcwmp,(IXML_Node *)faultstringcwmp_text);
	

	return doc;

}


IXML_Document *createSetFaultResponse(SoapHeader *sh, ParameterValueList *params, int * errors) {
	unsigned int i;
	IXML_Document *doc = ixmlDocument_createDocument();
	
	IXML_Element *envelope= ixmlDocument_createElementNS(doc, "http://schemas.xmlsoap.org/soap/envelope/", "soap:Envelope");
	ixmlElement_setAttribute(envelope,"xmlns:soap","http://schemas.xmlsoap.org/soap/envelope/" );
	ixmlElement_setAttribute(envelope,"soap:encodingStyle","http://schemas.xmlsoap.org/soap/encoding/" );
	ixmlElement_setAttribute(envelope,"xmlns:cwmp", "urn:dslforum-org:cwmp-1-0" );
	ixmlNode_appendChild( (IXML_Node *)doc,(IXML_Node *) envelope);

	if(sh!=NULL) {
		IXML_Node *header = createHeader(doc, sh);
		ixmlNode_appendChild( (IXML_Node *)envelope,(IXML_Node *)header);	
	}

	IXML_Element *body=ixmlDocument_createElementNS(doc, "http://schemas.xmlsoap.org/soap/envelope/", "soap:Body");
	ixmlNode_appendChild( (IXML_Node *)envelope,(IXML_Node *)body);

	IXML_Element *fault=ixmlDocument_createElementNS(doc, "http://schemas.xmlsoap.org/soap/envelope/", "soap:Fault");
	ixmlNode_appendChild( (IXML_Node *)body,(IXML_Node *)fault);

	IXML_Element *faultcode=ixmlDocument_createElementNS(doc, "http://schemas.xmlsoap.org/soap/envelope/", "faultcode");
	ixmlNode_appendChild( (IXML_Node *)fault,(IXML_Node *)faultcode);
	IXML_Node *faultcode_text= ixmlDocument_createTextNode(doc,"Client");
	ixmlNode_appendChild( (IXML_Node *)faultcode,(IXML_Node *)faultcode_text);
	
	IXML_Element *faultstring=ixmlDocument_createElementNS(doc, "http://schemas.xmlsoap.org/soap/envelope/", "faultstring");
	ixmlNode_appendChild( (IXML_Node *)fault,(IXML_Node *)faultstring);
	IXML_Node *faultstring_text= ixmlDocument_createTextNode(doc,"CWMP fault");
	ixmlNode_appendChild( (IXML_Node *)faultstring,(IXML_Node *)faultstring_text);
	
	IXML_Element *detail = ixmlDocument_createElementNS(doc, "http://schemas.xmlsoap.org/soap/envelope/", "detail");
	ixmlNode_appendChild( (IXML_Node *)fault,(IXML_Node *)detail);

	IXML_Element *faultcwmp=ixmlDocument_createElementNS(doc, "urn:dslforum-org:cwmp-1-0", "cwmp:Fault");
	ixmlNode_appendChild( (IXML_Node *)detail,(IXML_Node *)faultcwmp);


	IXML_Element *faultcodecwmp=ixmlDocument_createElementNS(doc, "urn:dslforum-org:cwmp-1-0", "FaultCode");
	ixmlNode_appendChild( (IXML_Node *)faultcwmp,(IXML_Node *)faultcodecwmp);
	IXML_Node *faultcodecwmp_text= ixmlDocument_createTextNode(doc,"9003");
	ixmlNode_appendChild( (IXML_Node *)faultcodecwmp,(IXML_Node *)faultcodecwmp_text);
	
	IXML_Element *faultstringcwmp=ixmlDocument_createElementNS(doc, "urn:dslforum-org:cwmp-1-0", "FaultString");
	ixmlNode_appendChild( (IXML_Node *)faultcwmp,(IXML_Node *)faultstringcwmp);
	IXML_Node *faultstringcwmp_text= ixmlDocument_createTextNode(doc, "Invalid arguments" );
	ixmlNode_appendChild( (IXML_Node *)faultstringcwmp,(IXML_Node *)faultstringcwmp_text);
	
	for(i=0;i<params->size;i++) {
		if(errors[i]!=0) {
			IXML_Element *setparamsfault =ixmlDocument_createElementNS(doc, "urn:dslforum-org:cwmp-1-0", "SetParameterValuesFault");
			ixmlNode_appendChild( (IXML_Node *)faultcwmp,(IXML_Node *)setparamsfault);

			IXML_Element *pn=ixmlDocument_createElementNS(doc, "urn:dslforum-org:cwmp-1-0", "ParameterName");
			ixmlNode_appendChild( (IXML_Node *)setparamsfault,(IXML_Node *)pn);
			IXML_Node *pn_text= ixmlDocument_createTextNode(doc,params->parameters[i].name);
			ixmlNode_appendChild( (IXML_Node *)pn,(IXML_Node *)pn_text);

			IXML_Element *fc=ixmlDocument_createElementNS(doc, "urn:dslforum-org:cwmp-1-0", "FaultCode");
			ixmlNode_appendChild( (IXML_Node *)setparamsfault,(IXML_Node *)fc);
			char a[5];
			sprintf(a, "%d", -errors[i]);
			IXML_Node *fc_text= ixmlDocument_createTextNode(doc,a);
			ixmlNode_appendChild( (IXML_Node *)fc,(IXML_Node *)fc_text);
			
			IXML_Element *fs=ixmlDocument_createElementNS(doc, "urn:dslforum-org:cwmp-1-0", "FaultString");
			ixmlNode_appendChild( (IXML_Node *)setparamsfault,(IXML_Node *)fs);
			IXML_Node *fs_text= ixmlDocument_createTextNode(doc,getErrorByNum(-errors[i]) );
			ixmlNode_appendChild( (IXML_Node *)fs,(IXML_Node *)fs_text);


		}

	}
	
	return doc;


}


/**************************************************/
/**************** HEADER CREATION *****************/
/**************************************************/


IXML_Node *createHeader(IXML_Document* doc, SoapHeader *sh) {
	IXML_Element *header=ixmlDocument_createElementNS(doc, "http://schemas.xmlsoap.org/soap/envelope/", "soap:Header");

	IXML_Element *id=ixmlDocument_createElementNS(doc, "urn:dslforum-org:cwmp-1-0", "cwmp:ID");
	ixmlElement_setAttribute(id,"soap:mustUnderstand", "1" );
	IXML_Node* id_text=ixmlDocument_createTextNode(doc, sh->id);
	ixmlNode_appendChild( (IXML_Node *) id, id_text);	
	ixmlNode_appendChild( (IXML_Node *)header,(IXML_Node *)id);

	if(sh->holdRequests!=0) {
		IXML_Element *holdreqs=ixmlDocument_createElementNS(doc, "urn:dslforum-org:cwmp-1-0", "cwmp:HoldRequests");
		ixmlElement_setAttribute(holdreqs,"soap:mustUnderstand", "1" );
		char *buf = (char *)malloc(4*sizeof(char) ) ;
		sprintf(buf, "%d", sh->holdRequests);
		IXML_Node* holdreqs_text=ixmlDocument_createTextNode(doc, buf );
		free(buf);
		ixmlNode_appendChild( (IXML_Node *) holdreqs, holdreqs_text);
		ixmlNode_appendChild( (IXML_Node *)header,(IXML_Node *)holdreqs);
	}

	if(sh->noMoreRequests!=0) {
		IXML_Element *nmr=ixmlDocument_createElementNS(doc, "urn:dslforum-org:cwmp-1-0", "cwmp:NoMoreRequests");
		char *buf = (char *)malloc(4*sizeof(char) ) ;
		sprintf(buf, "%d", sh->noMoreRequests);
		IXML_Node* nmr_text=ixmlDocument_createTextNode(doc, buf);
		free(buf);
		ixmlNode_appendChild( (IXML_Node *) nmr, nmr_text);
		ixmlNode_appendChild( (IXML_Node *)header,(IXML_Node *)nmr);
	}

	return (IXML_Node *)header;
}

